home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Prefs / MPPReadArgs.c < prev    next >
C/C++ Source or Header  |  1999-02-14  |  6KB  |  239 lines

  1. #include <proto/dos.h>
  2. #include <proto/icon.h>
  3. #include <workbench/workbench.h>
  4. #include "/modepro.h"
  5. #include "mpp.h"
  6.  
  7.  
  8. BOOL    GetReadArgs(void);
  9. BOOL    RAYesNo(STRPTR Str, BOOL DefVal);
  10. ULONG   RAInt(ULONG *Val,ULONG DefVal);
  11. STRPTR  RAString(STRPTR Str, STRPTR DefVal);
  12. BOOL    GetToolTypes(int argc, char **argv);
  13.  
  14. struct RDArgs *RArgs=0;
  15. LONG UseTT=0; 
  16.  
  17. extern ULONG  Arg_Promo, Arg_NLM, Arg_Ask, Arg_CH, Arg_CV, Arg_Debug, Arg_Import;
  18.  
  19. UBYTE RATemplate[]="FROM,"
  20.                    "EDIT/S,"
  21.                    "USE/S,"
  22.                    "SAVE/S,"
  23.                    "PUBSCREEN/K,"
  24.                    "PRO=ENABLE_PROMOTION/K,"
  25.                    "NLM=NEWLOOKMENUS/K,"
  26.                    "ASK=ASK_UNKNOWN/K,"
  27.                    "CH=CENTER_HORZ/K,"
  28.                    "CV=CENTER_VERT/K,"
  29.                    "FN=FONT_NAME/K,"
  30.                    "FS=FONT_SIZE/K/N,"
  31.                    "IMPORT/K,"
  32.                    "DEBUG/K";
  33.  
  34. LONG RAResults[14]={0};
  35.  
  36. #define FROM        0
  37. #define EDIT        1
  38. #define USE         2
  39. #define SAVE        3
  40. #define PUBSCREEN   4
  41. #define RA_PROMO    5
  42. #define RA_NLM      6
  43. #define RA_ASK      7
  44. #define RA_CAH      8
  45. #define RA_CAV      9
  46. #define FNAME      10
  47. #define FSIZE      11
  48. #define RA_IMPORT  12
  49. #define RA_DEBUG   13
  50.  
  51. WORD    ArgMode;
  52. struct DiskObject *MPIcon;
  53. BPTR OldDirLock;
  54.  
  55. BOOL GetArgs(int argc, char **argv)
  56. {
  57.   BPTR lock;
  58.   
  59.   ArgMode=min(argc,2);
  60.  
  61.   switch(ArgMode)
  62.   {
  63.     case 0:
  64.       return(GetToolTypes(argc,argv));
  65.       break;
  66.     case 1:
  67.       {
  68.         char pname[256];//                                                                             (4.61.4)
  69.         //                                                                                             (4.61.4)
  70.         if(GetProgramName(pname,256))//                                                                (4.61.4)
  71.         {//                                                                                            (4.61.4)
  72.           if(lock=DupLock(GetProgramDir()))//                                                          (4.61.4)
  73.           {//                                                                                          (4.61.4)
  74.             OldDirLock=CurrentDir(lock);//                                                             (4.61.4)
  75.             if(MPIcon=GetDiskObject(pname))//                                                          (4.61.4)
  76.             {//                                                                                        (4.61.4)
  77.               LONG l;
  78.                  
  79.               for(l=0;MPIcon->do_ToolTypes[l];l++);  // <- Note SEMI-COLON, Count ToolTypes
  80.                   
  81.               return(GetToolTypes(l,MPIcon->do_ToolTypes));
  82.             }
  83.           }
  84.         }
  85.       }
  86.       return(0);
  87.     case 2: // Shell Mode.
  88.       return(GetReadArgs());
  89.   }
  90.  
  91.  
  92. }
  93.  
  94. void CleanupArgs(void)
  95. {
  96.   BPTR lock;
  97.   
  98.   switch(ArgMode)
  99.   {
  100.     case 0:
  101.       ArgArrayDone();
  102.       break;
  103.     case 1:
  104.       ArgArrayDone();
  105.       FreeDiskObject(MPIcon);
  106.       lock=CurrentDir(OldDirLock);//                                                                             (4.56.2)
  107.       UnLock(lock);//                                                                                  (4.56.2)
  108.       break;
  109.     case 2:
  110.       FreeArgs(RArgs);
  111.       break;
  112.   }
  113. }
  114.  
  115. extern ULONG  ArgEdit,ArgUse,ArgSave;
  116. extern STRPTR ArgFrom,ArgPubscreen;
  117. extern UBYTE  *UserFontName;
  118. extern LONG   UserFontSize;
  119.  
  120.  
  121. BOOL GetReadArgs(void)
  122. {
  123.   if(RArgs=ReadArgs(RATemplate,RAResults,0))
  124.   {
  125.     if((Arg_Import    =(STRPTR)RAResults[RA_IMPORT]))
  126.     {
  127.       ArgEdit=TRUE;
  128.     }
  129.     else 
  130.     {
  131.       ArgFrom     =(STRPTR)RAResults[FROM];
  132.       ArgEdit     =RAResults[EDIT];
  133.       ArgUse      =RAResults[USE];
  134.       ArgSave     =RAResults[SAVE];
  135.       if(!ArgSave && !ArgUse)
  136.         ArgEdit=TRUE;
  137.     }
  138.  
  139.     ArgPubscreen  =(STRPTR)RAResults[PUBSCREEN];
  140.     UserFontName  =(STRPTR)RAResults[FNAME];
  141.     UserFontSize  =RAInt  ((ULONG *)RAResults[FSIZE],8);
  142.     
  143.     Arg_Promo     =RAYesNo((STRPTR)RAResults[RA_PROMO]  ,5);
  144.     Arg_NLM       =RAYesNo((STRPTR)RAResults[RA_NLM]    ,5);
  145.     Arg_Ask       =RAYesNo((STRPTR)RAResults[RA_ASK]    ,5);
  146.     Arg_CH        =RAYesNo((STRPTR)RAResults[RA_CAH]    ,5);
  147.     Arg_CV        =RAYesNo((STRPTR)RAResults[RA_CAV]    ,5);
  148.     Arg_Debug     =RAYesNo((STRPTR)RAResults[RA_DEBUG]  ,5);
  149.  
  150. //    printf("Exiting GRS\n");
  151.     
  152.     return(TRUE);
  153.   }
  154.   else
  155.     PrintFault(IoErr(),0);
  156.   return(FALSE);
  157. }
  158.  
  159. BOOL RAYesNo(STRPTR Str, BOOL DefVal)
  160. {
  161.   BOOL retval;
  162.   
  163.   retval=DefVal;
  164.   
  165.   if(Str)
  166.   {
  167.     switch(*Str)
  168.     {
  169.       case 'T':
  170.       case 't':
  171.       case 'Y':
  172.       case 'y':
  173.         retval=1;
  174.         break;
  175.       case 'F':
  176.       case 'f':
  177.       case 'N':
  178.       case 'n':
  179.         retval=0;
  180.     }
  181.   }
  182.   return(retval);
  183. }
  184.  
  185. ULONG RAInt(ULONG *Val,ULONG DefVal)
  186. {
  187.   if(Val)
  188.     return(*Val);
  189.   return(DefVal);
  190. }
  191.  
  192. STRPTR RAString(STRPTR Str, STRPTR DefVal)
  193. {
  194.   if(Str)
  195.     return(Str);
  196.   return(DefVal);
  197. }    
  198.  
  199. BOOL GetToolTypes(int argc, char **argv)
  200. {
  201.   UBYTE **ttypes;
  202.  
  203.   UseTT=TRUE;
  204.   
  205.   ttypes  =ArgArrayInit(argc,argv);
  206.   
  207.   if((Arg_Import    =ArgString(ttypes,(UBYTE *)"IMPORT",0)))
  208.   {
  209.     ArgEdit=TRUE;
  210.   }
  211.   else
  212.   {
  213.     ArgFrom =ArgString(ttypes,(UBYTE *)"FROM",0);  
  214.  
  215.     ArgEdit =(ULONG)FindToolType(ttypes,"EDIT");    
  216.     ArgUse  =(ULONG)FindToolType(ttypes,"USE");
  217.     ArgSave =(ULONG)FindToolType(ttypes,"SAVE");
  218.     if(!ArgSave && !ArgUse)
  219.       ArgEdit=TRUE;
  220.   }
  221.  
  222.   ArgPubscreen  =ArgString(ttypes,(UBYTE *)"PUBSCREEN",0);
  223.   UserFontName  =ArgString(ttypes,(UBYTE *)"FONT_NAME",0);
  224.   UserFontSize  =ArgInt   (ttypes,(UBYTE *)"FONT_SIZE",8);
  225.  
  226.   Arg_Promo     =ArgYesNo (ttypes,(UBYTE *)"ENABLE_PROMOTION",5);
  227.   Arg_NLM       =ArgYesNo (ttypes,(UBYTE *)"ENABLE_NLM",5);
  228.   Arg_Ask       =ArgYesNo (ttypes,(UBYTE *)"ASK_UNKNOWN",5);
  229.   Arg_CH        =ArgYesNo (ttypes,(UBYTE *)"CENTER_HORIZ",5);
  230.   Arg_CV        =ArgYesNo (ttypes,(UBYTE *)"CENTER_VERT",5);
  231.   Arg_Debug     =ArgYesNo (ttypes,(UBYTE *)"DEBUG",5);
  232.   Arg_Import    =ArgString(ttypes,(UBYTE *)"IMPORT",0);
  233.  
  234.   return(TRUE);
  235. //  return(FALSE);
  236. }
  237.  
  238.  
  239.